package com.medical.blood.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.medical.blood.entity.TestItem;
import com.medical.blood.service.imp.TestItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/testItem")
public class TestItemController {
    @Autowired
    private TestItemService testItemService;

    // 新增检测项目
    @PostMapping("/save")
    public boolean saveTestItem(@RequestBody TestItem testItem) {
        return testItemService.saveTestItem(testItem);
    }

    // 编辑检测项目
    @PostMapping("/update")
    public boolean updateTestItem(@RequestBody TestItem testItem) {
        return testItemService.updateTestItem(testItem);
    }

    // 根据分类查询检测项目列表
    @GetMapping("/listByCategory")
    public List<TestItem> listTestItemByCategory(String category) {
        return testItemService.listTestItemByCategory(category);
    }

    // 分页查询检测项目列表
    @GetMapping("/page")
    public Page<TestItem> page(int pageNum, int pageSize) {
        Page<TestItem> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<TestItem> wrapper = new LambdaQueryWrapper<>();
        return testItemService.page(page, wrapper);
    }
}